// pages/member/book/index.js
var t = getApp(),
  e = t.requirejs("core");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    route: "member_coupon",
    menu: t.tabBar,
    menu_show: false,
    now_time: Date.parse(new Date()) / 1000,
    show: false,
    loaded: false,
    list: [],
    status:0,
    page: 1,
    type:1
  },
  //底部导航跳转
  menu_url: function(k) {
    e.menu_url(k, 2);
  },
  onLoad: function(options) {

    if (options != null && options != undefined) {
      this.setData({
        tabbar_index: options.tabbar_index ? options.tabbar_index : -1
      });
    }

    e.setting();
    this.setData({
      menu: getApp().tabBar
    })

    if (this.data.tabbar_index >= 0) {
      this.setData({
        showtabbar: getApp().tabBar.IsDiDis ? getApp().tabBar.IsDiDis : false,
      })
    }

    this.getList()
  },
//切换
  unused: function(t) {
    console.log(t, "abc")
    var that = this,
      s = that.data.list,
      data = e.pdata(t),
      bb=e.pdata(t).type;
    console.log(data, "魏婴")
      this.setData({
        status:data.id,
        page:1,
        list:[],
        type:bb
      })
      that.getList();
  },

  getList: function() {
    var t = this;
    e.get("Market/UserCoupon", {
      page: t.data.page,
      user_id: getApp().getCache("userinfo").uid,
      status: t.data.status
    }, function(i) {
      if (i.code == 0) {
        var a = {
          show: true
        };
        i.info.length > 0 && (a.page = t.data.page + 1, a.list = t.data.list.concat(i.info), i.info.length < 10 && (a.loaded = true)), //concat() 方法用于连接两个或多个数组。
          i.info.length == 0 && (a.loaded = true);
        t.setData(a)
      } else {
        e.alert(i.msg)
      }

    }, true)
  },
  /**
   *上拉加载
   */
  onReachBottom: function() {
    this.data.loaded || this.getList()
  },
  url: function() {
    var url = '/yb_mingpian/pages/caregory/index';
    wx.navigateTo({
      url: url,
      fail: function(i) {
        if (i.errMsg.indexOf("tabbar") >= 0) {
          e.jump(url, 4)
        }
      }
    })

  },
  /**
   *下拉刷新
   */
  onPullDownRefresh: function() {
    this.setData({
        page: 1,
        list: [],
        loaded: false
      }),
      this.getList()
    wx.stopPullDownRefresh()
  },
  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function() {
  //
  // }
})